//
//  ShopDetailView.swift
//  SortProject
//
//  Created by ALH000355 on 2022/7/11.
//

import UIKit

class ShopDetailView: UIView, UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate {
    
    var tableView: UITableView!
    var navView: UIView!
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        uiConfig()
    }
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    func uiConfig() -> Void {
        backgroundColor = .cyan
        
        tableView = UITableView.init(frame: CGRect.zero, style: .plain)
        addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.left.top.right.bottom.equalTo(self)
        }
        tableView.delegate = self
        tableView.dataSource = self
        tableView.tableFooterView = UIView.init()
        tableView.estimatedRowHeight = 44.0
        tableView.rowHeight = UITableView.automaticDimension
        tableView.register(SDHeaderInfoCell.self, forCellReuseIdentifier: "aa")
        tableView.register(SDPhoneCell.self, forCellReuseIdentifier: "bb")
        tableView.register(SDEvaluateCell.self, forCellReuseIdentifier: "cc")
        tableView.contentInsetAdjustmentBehavior = .never
        
        createNavbar()
    }
    func createNavbar() -> Void {
        navView = UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 88))
        navView.backgroundColor = .white
        self.addSubview(navView)
        navView.isHidden = true
    }
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let contentOffSetY = scrollView.contentOffset.y
//        print("contentOffSetY->\(contentOffSetY)")
        
        if contentOffSetY <= 0 {
            navView.isHidden = true
            navView.alpha = 1
        } else if contentOffSetY < 145 {
            navView.alpha = contentOffSetY / 145.0
            navView.isHidden = false
        } else {
            navView.alpha = 1
            navView.isHidden = false
        }
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.section == 0 {
            let cell = tableView.dequeueReusableCell(withIdentifier: "aa") as! SDHeaderInfoCell
            cell.selectionStyle = .none
            return cell
        } else if indexPath.section == 1 {
            let cell = tableView.dequeueReusableCell(withIdentifier: "bb") as! SDPhoneCell
            cell.selectionStyle = .none
            return cell
        } else {
            let cell = tableView.dequeueReusableCell(withIdentifier: "cc") as! SDEvaluateCell
            cell.selectionStyle = .none
            return cell
        }
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return 1
        } else {
            return 5
        }
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return 3
    }

}
